package com.example.controller.frontend;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.example.common.ApiResult;
import com.example.entity.VisitHistory;
import com.example.service.VisitHistoryService;
import com.example.vo.VisitHistoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/visitHistory")
@Api(tags = "观看历史")
public class FrontendVisitHistoryController {


    @Resource
    private VisitHistoryService visitHistoryService;

    /**
     * 显示全部数据
     * @return
     *//*

    @PostMapping("/findAll")
    @ApiOperation("查看全部列表")
    public ApiResult<List<VisitHistory>> list(){
        List<VisitHistory> list = visitHistoryService.list();
        return ApiResult.ok(list);
        *//*http://localhost:8080/api/visitHistory/listAll*//*
    }

    *//**
     * 查看最新的数据num条。
     * @param num
     * @return
     *//*
    @GetMapping("/listByLimit/{num}")
    @ApiOperation("查看最新的数据num条数据")
    *//*  http://localhost:8080/api/visitHistory/findByLimit/2        *//*
    public ApiResult findByLimit(@PathVariable int num){
        List<VisitHistoryVO> byLimit = visitHistoryService.findByLimit(num);
        return ApiResult.ok(byLimit);
    }*/

    /**
     * 假删除
     * @param id 删除id
     * @return
     */

    @DeleteMapping("/Delete")
    @ApiOperation("移除")
    public ApiResult falseDeleteById(Integer id){
        Integer falseDelete = visitHistoryService.falseDelete(id);
        return ApiResult.ok(falseDelete);
    }

    @DeleteMapping("/DeleteAll")
    @ApiOperation("全部移除")
    public ApiResult falseDeleteAll(){
        Integer deleteAll = visitHistoryService.deleteAll();
        return ApiResult.ok(deleteAll);
    }

    /**
     * 存储上次播放的位置
     * @param id 用户id
     * @return
     */
    @GetMapping("/queryVisitLocation/{id}")
    @ApiOperation("存储上次播放的位置")
    public ApiResult queryVisitLocation(@PathVariable  Integer id){
        List<VisitHistory> visitHistories = visitHistoryService.queryVisitLocation(id);
        return ApiResult.ok(visitHistories);
    }


    @GetMapping("/queryPage/{courseName}/{page}/{size}")
    @ApiOperation("分页查询")
    public ApiResult queryPage(@PathVariable  int page ,
                                 @PathVariable  int size){
        Page<VisitHistory> visitHistoryPage = visitHistoryService.queryPage(page, size);
        PageDTO<VisitHistory> pageDTO = new PageDTO<>();
        pageDTO.setTotal(visitHistoryPage.getTotal());
        pageDTO.setRecords(visitHistoryPage.getRecords());
        return ApiResult.ok(pageDTO);
    }

}